package com.xiaolin.designmode.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName FlyweightFactory
 * @Description 享元工厂
 * @Detail detail
 * @Author MyPC
 * @Date 2020/11/3
 * @Version 1.0
 */
public class FlyweightFactory {
    private Map<String,Flyweight> map=new HashMap<>();
    public Flyweight flyweight(String key){
        Flyweight flyweight = map.get(key);
        if(flyweight !=null){
            System.out.println("具体享元角色已存在"+key+"已被成功获取");
        }else {
            flyweight=new ConcreteFlyweight(key);
            map.put(key,flyweight);
        }
        return flyweight;
    }
}
